Skip to content

[action] [PR:696] [sonic_pcie]: Fix regex string literals to use raw strings in pcie_common.py#698

Merged
mssonicbld merged 1 commit into
sonic-net:202511from
mssonicbld:cherry/202511/696
Jun 16, 2026
Merged

[action] [PR:696] [sonic_pcie]: Fix regex string literals to use raw strings in pcie_common.py#698
mssonicbld merged 1 commit into
sonic-net:202511from
mssonicbld:cherry/202511/696

Conversation

@mssonicbld

@mssonicbld mssonicbld commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Description

Updated regex patterns p1 and p2 in PcieUtil.get_pcie_device() to use raw string literals (r"...") instead of plain string literals.

Motivation and Context

On SONiC 20251110.35 (Debian 13 / Python 3.13), SyntaxWarning was emitted to stderr on every CLI invocation (show ver, show ip bgp sum, etc.) on Arista 7060X6-16PE-384C-B devices.

Root cause:

  • __pycache__/pcie_common.cpython-313.pyc was created by a root process with a restrictive umask, resulting in 0600 permissions.
  • Non-root admin users cannot read the 0600 .pyc -> Python falls back to parsing pcie_common.py from source on every CLI invocation.
  • pcie_common.py contains invalid escape sequences (\w, \s) in plain string regex patterns -> Python 3.13 emits SyntaxWarning on every parse.

Python 3.12+ warns on invalid escape sequences in plain strings; Python 3.13 raises SyntaxWarning; Python 3.14 will raise SyntaxError. Raw strings (r"...") are the correct and idiomatic way to write regex patterns and eliminate the warning regardless of .pyc cache state or permissions.

How Has This Been Tested?

  • Existing test suite passes: pytest tests/pcie_common_test.py -v
  • No DeprecationWarning or SyntaxWarning emitted under Python 3.12/3.13
  • No behavioral change - regex patterns are identical

Signed-off-by: Sonic Build Admin sonicbld@microsoft.com

…mmon.py

#### Description
Updated regex patterns `p1` and `p2` in `PcieUtil.get_pcie_device()` to use raw string literals (`r"..."`) instead of plain string literals.

#### Motivation and Context
Python 3.12+ emits `DeprecationWarning` for invalid escape sequences in regular string literals (e.g., `\w`, `\s`, `\(`), and Python 3.13 raises a `SyntaxWarning` for these. Without raw strings, sequences like `\w` and `\s` are technically undefined escape sequences that happen to work today but will become `SyntaxError` in a future Python release. Using raw string literals (`r"..."`) is the correct and idiomatic way to write regex patterns in Python.

#### How Has This Been Tested?
- Verified the existing test suite passes: `pytest tests/pcie_common_test.py -v`
- Confirmed no `DeprecationWarning` or `SyntaxWarning` is emitted under Python 3.12/3.13
- No behavioral change, the regex patterns themselves are identical

#### Additional Information (Optional)
This is a purely cosmetic/correctness fix. The regex logic and matched groups are unchanged.

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Original PR: #696

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld merged commit e0acb46 into sonic-net:202511 Jun 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant